import axios from 'axios'
import { Notify } from 'vant';
var instance = axios.create({
    // 请求的跟路径
    // baseURL: 'http://115.231.220.227:9999',
    baseURL :'http://localhost:9999',

    // 请求的超时时间
    timeout: 20000
});
instance.interceptors.request.use(function (config) {
    console.log('token',localStorage.getItem("token"))
    config.headers["token"] = localStorage.getItem("token");
    console.log('config',config)
    return config;
}, function (error) {
    return Promise.reject(error);
})
// 响应的拦截
instance.interceptors.response.use(function (response) {
    let status = response.status;
    switch (status) {
        case 200:
            if (response.data.code == 401) {
                Notify({ type: 'danger', message: response.data.message });
                return response
            }
            return response
        case 500:
            Notify({ type: 'danger', message: '系统异常' });
            return
        case 404:
            return
    }
}, function (error) {
    Notify({ type: 'danger', message: '系统异常' });
    return Promise.reject(error);
})
export function request(requestConfig) {
    return instance(requestConfig)
}